package com.example.litepal;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Content_add extends AppCompatActivity {

    private ImageView comeBack;
    private EditText ed_text;
    private ImageView del;
    private ImageView add;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_content_add);
        initView();
        inifunction();
    }


    private void initView() {
        comeBack = (ImageView) findViewById(R.id.comeBack);
        ed_text = (EditText) findViewById(R.id.ed_text);
        del = (ImageView) findViewById(R.id.del);
        add = (ImageView) findViewById(R.id.add);
    }

    private void inifunction() {
        //添加数据
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String text = ed_text.getText().toString().trim();
                if (TextUtils.isEmpty(text)) {
                    Toast.makeText(Content_add.this, "请输入要添加的内容", Toast.LENGTH_SHORT).show();
                    return;
                }
                SimpleDateFormat format = new SimpleDateFormat("YYYY年MM月dd HH:mm:ss");
                Date date = new Date();
                Info info = new Info(text, format.format(date));
                info.save();
                Toast.makeText(Content_add.this, "保存成功！", Toast.LENGTH_SHORT).show();
                finish();
            }
        });
        //删除
        del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed_text.setText("");
            }
        });

        //返回
        comeBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }


}